package com.abe.abetest.base;

import android.app.Application;
import android.content.Context;

import com.abe.abetest.album.MediaLoader;
import com.abe.libcore.AbeApplication;
import com.abe.libcore.utils.CrashHandler;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumConfig;

import java.util.Locale;

public class MainApplication extends AbeApplication {

    private static Application application;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        initCrashHandler();
        startNetWorkReceiver();
        initAlbum();
    }

    public static Application getInstance() {
        return application == null ? new MainApplication() : application;
    }

    public static Context getContext() {
        return getInstance().getApplicationContext();
    }

    public void initCrashHandler() {
        CrashHandler handler = CrashHandler.getInstance();
        handler.init(this);
    }

    protected void initAlbum() {
        Album.initialize(AlbumConfig.newBuilder(this)
                .setAlbumLoader(new MediaLoader())
                .setLocale(Locale.getDefault())
                .build()
        );
    }
}